package com.shop.cereshop.app.tencent.im.model.transfer;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.shop.cereshop.commons.tencent.im.enums.transfer.TransferOrderStatusEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @description: 发送转账订单请求参数
 * @author zdd
 * @date 2025/9/3 14:36
 * @version 1.0
 */
@ApiModel("发送转账订单请求参数")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CreateTransferOrderParam implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("发送者ID")
    private String senderId;

    @ApiModelProperty("发送者名称")
    @JsonIgnore
    private String senderName;

    @ApiModelProperty("群组ID (如果是单聊则为空)")
    private String groupId;

    @ApiModelProperty("接收者ID")
    @NotBlank(message = "receiverId不能为空")
    private String receiverId;

    @ApiModelProperty("接收者名称")
    @JsonIgnore
    private String receiverName;


    @ApiModelProperty("转账金额 (单位：元)")
    @NotNull(message = "amount不能为空")
    @DecimalMin(value = "0.01", message = "amount不能小于0.01元")
//    @DecimalMax(value = "200.00", message = "amount不能大于200元")
    private BigDecimal amount;

    @ApiModelProperty("备注")
    @Size(max = 20, message = "祝福语长度不能超过20个字符")
    private String remark;

    /**
     * 转换为TransferOrder对象
     * @return TransferOrder 转账订单实体对象
     */
    public TransferOrder covertToTransferOrder() {
        TransferOrder transferOrder = new TransferOrder();
        transferOrder.setSenderId(this.getSenderId());
        transferOrder.setSenderName(this.getSenderName());
        transferOrder.setGroupId(this.getGroupId());
        transferOrder.setReceiverId(this.getReceiverId());
        transferOrder.setAmount(this.getAmount());
        transferOrder.setFee(this.getAmount().multiply(new BigDecimal("0")));
        transferOrder.setActualAmount(this.getAmount().subtract(transferOrder.getFee()));
        transferOrder.setRemark(this.getRemark());
        transferOrder.setStatus(TransferOrderStatusEnum.PENDING_PAY.getCode());
        transferOrder.setCreateTime(LocalDateTime.now());
        return transferOrder;
    }


}
